<?php

namespace app\model;

use think\Model;

class OrderTuanzhang extends Model
{

	protected $connection = 'mysql';

	protected $pk = 'id';

	protected $name = 'order_tuanzhang';

	public static function gettzid($order_id)
	{
		$tuanzhang = self::where('order_id', $order_id)->order('id desc')->find();
		return $tuanzhang->tzid;
	}
	public static function is_tuanzhang($order_id)
	{
		$tuanzhang = self::where('order_id', $order_id)->order('id desc')->find();
		return $tuanzhang->id;
	}

	public static function tuanzhang($order_id)
	{
		$tuanzhang = self::where('order_id', $order_id)->order('id desc')->find();
		return Tuanzhang::getTitlebyid($tuanzhang->tzid);
	}

	public static function getTuanzhang($order_id)
	{
		$tuanzhang = self::where('order_id', $order_id)->order('id desc')->find();
		return Tuanzhang::getInfo($tuanzhang->tzid);
	}

	public static function addtuanzhang($order_tuanzhang)
	{
		$order =  self::where(['order_id' => $order_tuanzhang['order_id']])->select()->toArray();
		if (!empty($order)) {
			$res = self::where(['order_id' => $order_tuanzhang['order_id']])->update(['tzid' => $order_tuanzhang['tzid']]);
		} else {
			$res = self::create($order_tuanzhang);
		}

		return $res;
	}
}
